package com.bree.erp.jsf.view.pr;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import org.apache.log4j.Logger;
import org.primefaces.model.LazyDataModel;

import com.bree.erp.entity.PurchaseRequisition;
import com.bree.erp.entity.Status;
import com.bree.erp.jsf.datatable.LazyBreeDataModel;
import com.bree.erp.jsf.httpsess.UserSessionData;
import com.bree.erp.jsf.service.wrapper.PurchaseRequisitionWrapperServiceBean;
import com.bree.erp.service.PurchaseRequisitionWrapperService;

@ManagedBean(name = "dtArchivedPurchaseRequisitionsView")
@ViewScoped
public class ArchivedPurchaseRequisitionsView extends AbstractPurchaseRequisitionLazyView {

	private static final long serialVersionUID = 1L;
	
	private static Logger LOG = Logger.getLogger(ArchivedPurchaseRequisitionsView.class);
	
	@ManagedProperty(value="#{userSession}")
	private UserSessionData userSession;

	private LazyDataModel<PurchaseRequisition> lazyModel;
	
	public void init() {
		
		Long projectId = userSession.getProjectId();
		
		LOG.debug("Archived List: init for project#" + projectId);
		
		String userId = userSession.getLoggedInUser().getEmail();
		
		lazyModel = new LazyBreeDataModel<PurchaseRequisition, PurchaseRequisitionWrapperService, Long>(
				new PurchaseRequisitionWrapperServiceBean(purchaseRequisitionService, userId, projectId, Status.REJECTED,  Status.INPROGRESS, Status.REJECTED, Status.CLOSED, Status.CONFIRMED, Status.RECEIVED, Status.PARTIAL, Status.WITHDRAW), 0L);
		
	}

	/**
	 * @return the userSession
	 */
	public UserSessionData getUserSession() {
		return userSession;
	}

	/**
	 * @param userSession the userSession to set
	 */
	public void setUserSession(UserSessionData userSession) {
		this.userSession = userSession;
	}

	@Override
	public LazyDataModel<PurchaseRequisition> getLazyModel() {
		
		init();
		
		return lazyModel;
	}
}
